﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Nauka.engine
{
    public class Card
    {
        public Rank rank { get; set; }
        public Color color { get; set; }

        public Card(Rank r, Color c)
        {
            rank = r;
            color = c;
        }

        public Card(int int_value)
        {
            rank = (Rank)(int_value / 4);
            color = (Color)(int_value % 4);
        }

        public static string getColorString(Card c){
            string card;
            
            switch (c.color)
            {
                case Color.Clubs:
                    card = "c";
                    break;
                case Color.Diamonds:
                    card = "d";
                    break;
                case Color.Hearts:
                    card = "h";
                    break;
                default:
                    card = "s";
                    break;
            }
            return card;
        }


        public int intValue()
        {
            return (int)rank * 4 + (int)color;
        }

        public static string stringValue(int v)
        {
            int rank = v / 4;
            int color = v % 4;

            string card;

            switch (rank)
            {
                case 8:
                    card = "T";
                    break;
                case 9:
                    card = "J";
                    break;
                case 10:
                    card = "Q";
                    break;
                case 11:
                    card = "K";
                    break;
                case 12:
                    card = "A";
                    break;
                default:
                    card = (string)Convert.ToString(rank + 2);
                    break;
            }
            switch (color)
            {
                case 0:
                    card += "c";
                    break;
                case 1:
                    card += "d";
                    break;
                case 2:
                    card += "h";
                    break;
                default:
                    card += "s";
                    break;
            }

            return card;
        }

        public Card(string str_card)
        {
            Console.WriteLine(str_card + " " + str_card.Substring(0, 1) + " " + str_card.Substring(1, 1));
            switch (str_card.Substring(0,1))
            {
                case "2" :
                    rank = Rank.Deuce;
                    break;
                case "3" :
                    rank = Rank.Three;
                    break;
                case "4":
                    rank = Rank.Four;
                    break;
                case "5":
                    rank = Rank.Five;
                    break;
                case "6":
                    rank = Rank.Six;
                    break;
                case "7":
                    rank = Rank.Seven;
                    break;
                case "8":
                    rank = Rank.Eight;
                    break;
                case "9":
                    rank = Rank.Nine;
                    break;
                case "T":
                    rank = Rank.Ten;
                    break;
                case "J":
                    rank = Rank.Jack;
                    break;
                case "Q":
                    rank = Rank.Queen;
                    break;
                case "K":
                    rank = Rank.King;
                    break;
                default:
                    rank = Rank.Ace;
                    break;
            }
            switch (str_card.Substring(1, 1))
            {
                case "c":
                    color = Color.Clubs;
                    break;
                case "d":
                    color = Color.Diamonds;
                    break;
                case "h":
                    color = Color.Hearts;
                    break;
                default:
                    color = Color.Spades;
                    break;
            }
        }
    }
}
